$(function () {
    $.idcode.setCode();
    $("form").on("submit", function (e) {
        var IsBy = $.idcode.validateCode();//调用返回值，返回为true或false
        if (IsBy) {

            $.ajax({
                url: "http:./../server/loginServer.php",
                data: $("form").serialize(),
                async: true,
                type: "post",
                dataType: "json"
            }).then(function (res) {
                console.log(res)
                var showIcom = res.status == 1 ? 1 : 2;
                layer.alert(res.msg + ',是否去主页',
                    {
                        icon: showIcom,
                        title: "登录消息提示",
                        btn: ['是的', '不去']
                        , anim: 4 //动画类型
                    }, function () {
                        location = "./zhuye.html";
                        localStorage.setItem("user", JSON.stringify(res.data));
                    }, function (index) {
                        layer.close(index);
                    });
            })
        }else {
            layer.msg("验证码错误")
        }

        e.preventDefault();
    })
})